﻿<template>
  <div class="busStroe-container">
    <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="门店名称">
          <el-input v-model="queryParams.sName" clearable="" placeholder="请输入门店名称"/>
          
        </el-form-item>
        <!-- <el-form-item label="省">
          <el-input v-model="queryParams.province" clearable="" placeholder="请输入省"/>
          
        </el-form-item>
        <el-form-item label="市">
          <el-input v-model="queryParams.city" clearable="" placeholder="请输入市"/>
          
        </el-form-item>
        <el-form-item label="区">
          <el-input v-model="queryParams.area" clearable="" placeholder="请输入区"/>
          
        </el-form-item> -->

        <el-form-item label="省">
           <el-select v-model="queryParams.province" filterable placeholder="请输入省" @change="getCity">
                <el-option value="">无</el-option>
                <el-option v-for="dict in provinceList" :key="dict.id" :value="dict.name" :label="dict.name">
                  {{ dict.name }}
                </el-option>
              </el-select>
          <!-- <el-input v-model="queryParams.province" clearable="" placeholder="请输入省"/> -->
          
        </el-form-item>
        <el-form-item label="市">
          <el-select v-model="queryParams.city" filterable placeholder="请输入市"  @change="getArea">
                <el-option value="">无</el-option>
                <el-option v-for="dict in cityList" :key="dict.id" :value="dict.name" :label="dict.name">
                  {{ dict.name }}
                </el-option>
              </el-select>
          <!-- <el-input v-model="queryParams.city" clearable="" placeholder="请输入市"/> -->
          
        </el-form-item>
        <el-form-item label="区">
          <el-select v-model="queryParams.area" filterable placeholder="请输入区">
                <el-option value="">无</el-option>
                <el-option v-for="dict in areaList" :key="dict.id" :value="dict.name" :label="dict.name">
                  {{ dict.name }}
                </el-option>
              </el-select>
          <!-- <el-input v-model="queryParams.area" clearable="" placeholder="请输入区"/> -->
          
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="queryParams.address" clearable="" placeholder="请输入地址"/>
          
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="queryParams.phone" clearable="" placeholder="请输入电话"/>
          
        </el-form-item>
        <el-form-item label="主体">
          <el-input v-model="queryParams.company" clearable="" placeholder="请输入主体"/>
          
        </el-form-item>
        <el-form-item label="纳税人识别号">
          <el-input v-model="queryParams.taxpayNo" clearable="" placeholder="请输入纳税人识别号"/>
          
        </el-form-item>
        <el-form-item label="来源">
          <el-input-number v-model="queryParams.source"  clearable="" placeholder="请输入来源"/>
          
        </el-form-item>
        <el-form-item>
          <el-button-group>
            <el-button type="primary"  icon="ele-Search" @click="handleQuery" v-auth="'busStroe:page'"> 查询 </el-button>
            <el-button icon="ele-Refresh" @click="() => queryParams = {}"> 重置 </el-button>
            
          </el-button-group>
          
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="ele-Plus" @click="openAddBusStroe" v-auth="'busStroe:add'"> 新增 </el-button>
          
        </el-form-item>
        
      </el-form>
    </el-card>
    <el-card class="full-table" shadow="hover" style="margin-top: 8px">
      <el-table
				:data="tableData"
				style="width: 100%"
				v-loading="loading"
				tooltip-effect="light"
				row-key="id"
				border="">
        <el-table-column type="index" label="序号"   width="55" show-overflow-tooltip="" align="center"/>
         <el-table-column prop="id" label="主键Id"   show-overflow-tooltip="" />
         <el-table-column prop="tenantId" label="租户Id"   show-overflow-tooltip="" />
         <el-table-column prop="sName" label="门店名称"   show-overflow-tooltip="" />
         <el-table-column prop="loginId" label="用户账号Id"   show-overflow-tooltip="" />
         <el-table-column prop="sysUserRealName" label="用户"   show-overflow-tooltip="" />
         <el-table-column prop="province" label="省"   show-overflow-tooltip="" />
         <el-table-column prop="city" label="市"   show-overflow-tooltip="" />
         <el-table-column prop="area" label="区"   show-overflow-tooltip="" />
         <el-table-column prop="provinceName" label="省"   show-overflow-tooltip="" />
         <el-table-column prop="cityName" label="市"   show-overflow-tooltip="" />
         <el-table-column prop="areaName" label="区"   show-overflow-tooltip="" />
         <el-table-column prop="address" label="地址"   show-overflow-tooltip="" />
         <el-table-column prop="phone" label="电话"   show-overflow-tooltip="" />
         <el-table-column prop="company" label="主体"   show-overflow-tooltip="" />
         <el-table-column prop="taxpayNo" label="纳税人识别号"   show-overflow-tooltip="" />
         <el-table-column prop="source" label="来源"   show-overflow-tooltip="" />
         <el-table-column prop="createTime" label="创建时间"   show-overflow-tooltip="" />
         <el-table-column prop="updateTime" label="更新时间"   show-overflow-tooltip="" />
         <el-table-column prop="createUserId" label="创建者Id"   show-overflow-tooltip="" />
         <el-table-column prop="updateUserId" label="修改者Id"   show-overflow-tooltip="" />
         <el-table-column prop="createUserName" label="创建者"   show-overflow-tooltip="" />
        <el-table-column prop="updateUserName" label="修改者" show-overflow-tooltip=""/>
        <el-table-column prop="isDelete" label="是否启用" show-overflow-tooltip="">
          <template #default="scope">
            <el-tag v-if="scope.row.isDelete"> 是 </el-tag>
            <el-tag type="danger" v-else=""> 否 </el-tag>
            
          </template>
          
        </el-table-column>
        <el-table-column label="操作" width="300" align="center" fixed="right" show-overflow-tooltip="" v-if="auth('busStroe:edit') || auth('busStroe:delete')">
          <template #default="scope">
            <el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditBusStroe(scope.row)" v-auth="'busStroe:edit'"> 编辑 </el-button>
            <el-button icon="ele-Memo" size="small" text type="primary" @click="openDictDataDialog(scope.row)" v-auth="'busStroe:page'"> 明细 </el-button>
            <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delBusStroe(scope.row)" v-auth="'busStroe:delete'"> 停用 </el-button>
            <el-button icon="ele-Check" size="small" text="" type="primary" @click="isEnable(scope.row)" v-auth="'busStroe:page'"> 启用 </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100]"
				small=""
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
	/>
      <editDialog  ref="editDialogRef"  :title="editBusStroeTitle" :loginId="loginId"  @reloadTable="handleQuery" />
      <dictDataDialog ref="dictDataDialogRef" :isShowDialog="isShowDialog" />
    </el-card>
  </div>
</template>

<script lang="ts" setup="" name="busStroe">
  import { ref } from "vue";
  import { ElMessageBox, ElMessage } from "element-plus";
  import { auth } from '/@/utils/authFunction';
  //import { formatDate } from '/@/utils/formatTime';
  import mittBus from '/@/utils/mitt';
  import { getAPI } from '/@/utils/axios-utils';
  import editDialog from '/@/views/main/busStroe/component/editDialog.vue'
  import { pageBusStroe, deleteBusStroe ,setEnable} from '/@/api/main/busStroe';
  import { getSysRegionList,getProvinceList,getCityList,getAreaList}  from '/@/api/main/sysCity';
  import StoreUserDialog from '/@/views/main/busStroe/component/storeUserDialog.vue';
  import dictDataDialog from './component/storeUserDialog.vue';

  const dictDataDialogRef = ref<InstanceType<typeof StoreUserDialog>>();
  const isShowDialog = ref(false);

    const editDialogRef = ref();
    const loading = ref(false);
    const tableData = ref<any>
      ([]);

      const loginId = ref('');

      const queryParams = ref<any>
        ({});
        const tableParams = ref({
        page: 1,
        pageSize: 10,
        total: 0,
        });
        const editBusStroeTitle = ref("");
        const getCity=async (val:any)=>{
          const res= await getCityList({name:val})
          cityList.value=res.data.result;
        }
        const getArea=async (val:any)=>{
          const res= await getAreaList({name:val})
          areaList.value=res.data.result;
        }

        // 查询操作
        const handleQuery = async () => {
        loading.value = true;
        var res = await pageBusStroe(Object.assign(queryParams.value, tableParams.value));
        tableData.value = res.data.result?.items ?? [];
        tableParams.value.total = res.data.result?.total;
        loading.value = false;
        };

        // 打开新增页面
        const openAddBusStroe = () => {
        editBusStroeTitle.value = '添加门店';
        editDialogRef.value.openDialog({});
        };

       
        // 打开编辑页面
        const openEditBusStroe = (row: any) => {
          loginId.value = row.loginId;
        editBusStroeTitle.value = '编辑门店';
        editDialogRef.value.openDialog(row);
        };
        //明细
        const openDictDataDialog = (row: any) => {
	        // console.log(row);
	        dictDataDialogRef.value?.openDialog(row);
        };

        // 停用
        const delBusStroe = (row: any) => {
        ElMessageBox.confirm(`确定要停用吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        })
        .then(async () => {
        await deleteBusStroe(row);
        handleQuery();
        ElMessage.success("停用成功");
        })
        .catch(() => {});
        };
        // 启用
        const isEnable = async(row: any) => {
         
         await isEnable(row);
         handleQuery();
         ElMessage.success("启用成功");
        
         };

        // 改变页面容量
        const handleSizeChange = (val: number) => {
        tableParams.value.pageSize = val;
        handleQuery();
        };

        // 改变页码序号
        const handleCurrentChange = (val: number) => {
        tableParams.value.page = val;
        handleQuery();
        };

 // 初始化
     
 const sysRegionList = ref<any>([]);
        const provinceList = ref<any>([]);
        const cityList = ref<any>([]);
        const areaList = ref<any>([]);
        const Init = async () => {
        //初始化-行政区划
        
        await getSysRegionList().then(res => {
          if(res.data.code==200) {
            for(var i=0; i<res.data.result.length; i++) {
              var ele = {
                id: res.data.result[i].id,
                name: res.data.result[i].name
              };
              sysRegionList.value.push(ele);
            }
          }
        });
        await getProvinceList().then(res => {
          if(res.data.code==200) {
            for(var i=0; i<res.data.result.length; i++) {
              var ele = {
                id: res.data.result[i].id,
                name: res.data.result[i].name
              };
              provinceList.value.push(ele);

            }
          }
        });
    };




handleQuery();
Init();
</script>


